package com.efuture.chaptersix

/* @Description:Kotlin语言[]操作符学习
 * @Auther: zhaoshanshan
 * @Date: 2022/03/08/3:31 下午
 */
class Demo101<T>(vararg objects:T,private val flag:Boolean){
     private val objectArray:Array<out T> = objects

     //运算符重载 重载的是[]
    operator fun get(index:Int) = objectArray[index].takeIf { flag }


}
fun main() {
    val d = Demo101("赵山山",123,true,null,flag = true)
    println(d[0])//使用的重载运算符 可以直接[index]
    println(d[1])
    println(d[2])
    println(d[3])


}